package com.cirkana.viewer.route.model.gpx;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;

public class RouteController {

	protected static Metadata createMetadata() {
		return new Metadata();
	}

	protected static Metadata createMetadata(String name, String desc,
			String author, String preview) {
		Metadata metadata = createMetadata();
		metadata.setName(name);
		metadata.setDesc(desc);
		metadata.setAuthor(author);
		metadata.setPreview(preview);
		return metadata;
	}

	protected static WayPoint createWayPoint() {
		return new WayPoint();
	}

	protected static WayPoint createWayPoint(Double lat, Double lon,
			Double ele, Date time, String name, String cmt, String desc) {
		WayPoint wayPoint = createWayPoint();
		wayPoint.setLat(lat);
		wayPoint.setLon(lon);
		wayPoint.setEle(ele);
		wayPoint.setTime(time);
		wayPoint.setName(name);
		wayPoint.setCmt(cmt);
		wayPoint.setDesc(desc);
		return wayPoint;
	}

	protected static TrackPoint createTrackPoint() {
		return new TrackPoint();
	}

	protected static TrackPoint createTrackPoint(Double lat, Double lon,
			Double ele, Date time) {
		TrackPoint trackPoint = createTrackPoint();
		trackPoint.setLat(lat);
		trackPoint.setLon(lon);
		trackPoint.setEle(ele);
		trackPoint.setTime(time);
		return trackPoint;
	}

	protected static Track createTrack() {
		return new Track();
	}

	protected static Track createTrack(String name, String desc, String cmt) {
		Track track = createTrack();
		track.setName(name);
		track.setDesc(desc);
		track.setCmt(cmt);
		return track;
	}

	protected static Track createTrack(String name, String desc, String cmt,
			ArrayList<TrackPoint> trackPoints) {
		Track track = createTrack(name, desc, cmt);
		track.setTrackPoints(trackPoints);
		return track;
	}

	protected static Track addTrackPoint(Track track, TrackPoint trackPoint) {
		if (track.getTrackPoints() == null)
			track.setTrackPoints(new ArrayList<TrackPoint>());
		track.getTrackPoints().add(trackPoint);
		return track;
	}

	protected static Track addTrackPoint(Track track, Double lat, Double lon,
			Double ele, Date time) {
		return addTrackPoint(track, createTrackPoint(lat, lon, ele, time));
	}

	public static Tracker loadGpxTracker(InputStream inputStream)
			throws GpxTrackerException {
		return GpxTrackerParser.getTracker(inputStream);
	}

	public static Tracker createTracker() {
		return new Tracker();
	}

	protected static Tracker addTrack(Tracker tracker, Track track) {
		if (tracker.getTracks() == null)
			tracker.setTracks(new ArrayList<Track>());
		tracker.getTracks().add(track);
		return tracker;
	}

	protected static Tracker addWayPoint(Tracker tracker, WayPoint wayPoint) {
		if (tracker.getWayPoints() == null)
			tracker.setWayPoints(new ArrayList<WayPoint>());
		tracker.getWayPoints().add(wayPoint);
		return tracker;
	}

}
